﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ksp.Controller
{
    public static class ActionParser
    {
        public static String KeyWord = "ACTIONS";

        private static String actionGroup = "actionGroup = ";
        
        private const string bracketOpen = "{";
        private const string bracketClose = "}";

        public static List<Model.Action> ParseAction(List<String> lines)
        {
            List<Model.Action> actions = new List<Model.Action>();
            bool iterate = true;
            int lineNo = 1; // skip first bracket from EVENTS-Tag
            int lineMax = lines.Count - 1;
            while (lineNo < lineMax && iterate)
            {
                string Line = lines[lineNo];
                if (Line == bracketOpen)
                {
                    Model.Action ac = new Model.Action();
                    ac.Title = lines[lineNo - 1]; // get Event Title
                    lineNo++; // and jump into content
                    while (lineNo < lineMax && Line != bracketClose)
                    {
                        Line = lines[lineNo];

                        if (Line.StartsWith(actionGroup))
                            ac.Groups = Line.Replace(actionGroup, String.Empty).Replace(", ",Environment.NewLine);
                        
                        lineNo++;
                    }
                    actions.Add(ac);
                }
                else
                    lineNo++;
            }
            return actions;
        }
    }
}
